<template>
  <el-container class="dashboard-layout">
    <!-- 侧边栏 -->
    <el-aside width="auto" class="sidebar-container" :class="{ 'is-collapsed': isCollapse }">
      <Navigator />
      <div class="collapse-control" @click="toggleCollapse">
        <el-icon :size="20">
          <component :is="isCollapse ? 'DArrowRight' : 'DArrowLeft'" />
        </el-icon>
      </div>
    </el-aside>

    <el-container class="main-container">
      <el-main class="main-content">
        <!-- 欢迎头部 -->
        <div class="welcome-header">
          <div class="welcome-text">
            <h1>DNS 安全态势感知系统</h1>
            <p>实时监控全国 DNS 递归服务器安全状况</p>
          </div>
          <div class="header-decoration">
            <div class="floating-shapes">
              <div class="shape shape-1"></div>
              <div class="shape shape-2"></div>
              <div class="shape shape-3"></div>
            </div>
          </div>
        </div>

        <!-- 主要内容区域 -->
        <div class="dashboard-grid">
          <!-- 左侧统计面板 -->
          <div class="grid-item stats-panel">
            <div class="card-wrapper">
              <div class="card-header">
                <h3>今日统计概览</h3>
                <div class="header-line"></div>
              </div>
              <div class="card-body">
                <DetailDataDaily />
              </div>
            </div>
          </div>

          <!-- 左侧趋势图表 -->
          <div class="grid-item chart-panel">
            <div class="card-wrapper">
              <div class="card-header">
                <h3>DNSSEC 支持趋势</h3>
                <div class="header-line"></div>
              </div>
              <div class="card-body">
                <DnssecChart />
              </div>
            </div>
          </div>

          <!-- 中央地图区域 -->
          <div class="grid-item map-panel">
            <div class="card-wrapper map-card">
              <div class="card-header">
                <h3>全国态势分布</h3>
                <div class="header-line"></div>
              </div>
              <div class="card-body">
                <ChinaMap />
              </div>
            </div>
          </div>

          <!-- 中央数据表格 -->
          <div class="grid-item table-panel">
            <div class="card-wrapper">
              <div class="card-header">
                <h3>地区详细数据</h3>
                <div class="header-line"></div>
              </div>
              <div class="card-body">
                <RankChart />
              </div>
            </div>
          </div>

          <!-- 右侧错误分析 -->
          <div class="grid-item error-panel">
            <div class="card-wrapper">
              <div class="card-header">
                <h3>错误类型分析</h3>
                <div class="header-line"></div>
              </div>
              <div class="card-body">
                <DnssecErrorChart />
              </div>
            </div>
          </div>

          <!-- 右侧协议支持 -->
          <div class="grid-item protocol-panel">
            <div class="card-wrapper">
              <div class="card-header">
                <h3>安全协议支持</h3>
                <div class="header-line"></div>
              </div>
              <div class="card-body">
                <DnssecDotDoh />
              </div>
            </div>
          </div>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import { ref } from 'vue';
import {
  DArrowLeft,
  DArrowRight
} from '@element-plus/icons-vue';

import Navigator from "@/components/Navigator.vue";
import ChinaMap from "@/components/ChinaMap.vue";
import DetailDataDaily from "@/components/DetailDataDaily.vue";

import DnssecErrorChart from "@/components/DnssecErrorChart.vue";
import DnssecDotDoh from "@/components/DnssecDotDoh.vue";
import RankChart from "@/components/RankChart.vue";

const isCollapse = ref(false);

const toggleCollapse = () => {
  isCollapse.value = !isCollapse.value;
};
</script>

<style scoped>
.dashboard-layout {
  height: 100vh;
  overflow: hidden;
}

.sidebar-container {
  background: linear-gradient(145deg, #1a237e 0%, #0d47a1 50%, #01579b 100%);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
  z-index: 100;
}

.sidebar-container.is-collapsed {
  width: 64px;
}

.collapse-control {
  padding: 15px;
  text-align: center;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
}

.collapse-control:hover {
  background: rgba(255, 255, 255, 0.2);
}

.main-container {
  display: flex;
  height: 100%;
  width: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  position: relative;
  overflow: hidden;
}

.main-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    radial-gradient(circle at 20% 80%, rgba(120, 119, 198, 0.3) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(255, 121, 198, 0.3) 0%, transparent 50%),
    radial-gradient(circle at 40% 40%, rgba(140, 155, 255, 0.2) 0%, transparent 50%);
  z-index: 0;
}

.main-content {
  position: relative;
  z-index: 1;
  padding: 30px;
  height: 100%;
  overflow: auto;
}

/* 欢迎头部 */
.welcome-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
  padding: 25px 35px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  position: relative;
  overflow: hidden;
}

.welcome-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(45deg, rgba(255, 255, 255, 0.1) 0%, transparent 100%);
  z-index: -1;
}

.welcome-text h1 {
  font-size: 2.5em;
  font-weight: 700;
  color: white;
  margin: 0 0 10px 0;
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.3);
  background: linear-gradient(45deg, #fff, #e3f2fd);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-text p {
  font-size: 1.2em;
  color: rgba(255, 255, 255, 0.8);
  margin: 0;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.2);
}

.header-decoration {
  position: relative;
  width: 150px;
  height: 150px;
}

.floating-shapes {
  position: relative;
  width: 100%;
  height: 100%;
}

.shape {
  position: absolute;
  border-radius: 50%;
  animation: float 6s ease-in-out infinite;
}

.shape-1 {
  width: 60px;
  height: 60px;
  background: linear-gradient(45deg, #ff6b6b, #ff8e8e);
  top: 10px;
  left: 20px;
  animation-delay: 0s;
}

.shape-2 {
  width: 40px;
  height: 40px;
  background: linear-gradient(45deg, #4ecdc4, #44a08d);
  top: 80px;
  left: 70px;
  animation-delay: 2s;
}

.shape-3 {
  width: 30px;
  height: 30px;
  background: linear-gradient(45deg, #45b7d1, #96c93d);
  top: 40px;
  left: 100px;
  animation-delay: 4s;
}

@keyframes float {
  0%, 100% {
    transform: translateY(0px) rotate(0deg);
  }
  33% {
    transform: translateY(-20px) rotate(120deg);
  }
  66% {
    transform: translateY(10px) rotate(240deg);
  }
}

/* 网格布局 */
.dashboard-grid {
  display: grid;
  grid-template-columns: 300px 1fr 350px;
  grid-template-rows: 280px 1fr;
  gap: 25px;
  height: calc(100vh - 250px);
  max-height: 800px;
}

.grid-item {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  min-height: 0;
}

.stats-panel {
  grid-column: 1;
  grid-row: 1;
}

.chart-panel {
  grid-column: 1;
  grid-row: 2;
}

.map-panel {
  grid-column: 2;
  grid-row: 1;
}

.table-panel {
  grid-column: 2;
  grid-row: 2;
}

.error-panel {
  grid-column: 3;
  grid-row: 1;
}

.protocol-panel {
  grid-column: 3;
  grid-row: 2;
}

/* 卡片样式 */
.card-wrapper {
  height: 100%;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.card-wrapper::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, #667eea, #764ba2, #f093fb);
  z-index: 1;
}

.card-wrapper:hover {
  transform: translateY(-5px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
}

.map-card {
  background: rgba(255, 255, 255, 0.05);
}

.card-header {
  padding: 20px 25px 15px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  position: relative;
}

.card-header h3 {
  margin: 0;
  font-size: 1.3em;
  font-weight: 600;
  color: white;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.3);
}

.header-line {
  position: absolute;
  bottom: 0;
  left: 25px;
  right: 25px;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
}

.card-body {
  height: calc(100% - 80px);
  padding: 15px 20px 20px;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* 响应式设计 */
@media (max-width: 1400px) {
  .dashboard-grid {
    grid-template-columns: 280px 1fr 320px;
  }
}

@media (max-width: 1200px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(6, 300px);
    gap: 20px;
  }
  
  .stats-panel,
  .chart-panel,
  .map-panel,
  .table-panel,
  .error-panel,
  .protocol-panel {
    grid-column: 1;
  }
  
  .stats-panel { grid-row: 1; }
  .map-panel { grid-row: 2; }
  .chart-panel { grid-row: 3; }
  .table-panel { grid-row: 4; }
  .error-panel { grid-row: 5; }
  .protocol-panel { grid-row: 6; }
}

@media (max-width: 768px) {
  .main-content {
    padding: 20px;
  }
  
  .welcome-header {
    flex-direction: column;
    text-align: center;
    padding: 20px;
  }
  
  .welcome-text h1 {
    font-size: 2em;
  }
  
  .header-decoration {
    margin-top: 20px;
    width: 100px;
    height: 100px;
  }
  
  .dashboard-grid {
    height: auto;
    grid-template-rows: repeat(6, 250px);
  }
}

/* 滚动条样式 */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.5);
}
</style>